<form class="layui-form layui-card" action='{:url("editCity")}' data-auto="true" method="post" autocomplete="off">


    <div class="layui-form-item">
        <label class="layui-form-label">级别</label>
        <div class="layui-input-block">
            <select id="ccate" class="layui-select" lay-filter="demo" name="level_type" required>
                <option value=''>-- 请选择 --</option>
                <option value="1" {if isset($info.level_type) and $info.level_type eq 1} selected {/if}>省</option>
                <option value="2" {if isset($info.level_type) and $info.level_type eq 2} selected {/if}>市</option>
                <option value="3" {if isset($info.level_type) and $info.level_type eq 3} selected {/if}>区</option>

            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上级</label>
        <div class="layui-input-block">
            <select lay-search id="p_channel" class="layui-select" lay-filter="demo1" name="parent_id" required>
                <option value=''>{$info.merger_name|default=""}</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input name="name" value='{$info.name|default=""}' required placeholder="请填写地区名" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">经度</label>
        <div class="layui-input-block">
            <input name="lng" value='{$info.lng|default=""}' required placeholder="请输入经度" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">纬度</label>
        <div class="layui-input-block">
            <input name="lat" value='{$info.lat|default=""}' required placeholder="请输入纬度" class="layui-input">
        </div>
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
</form>

<script>form.render()</script>
<script>
    layui.use(['layer', 'jquery', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        form.on('select(demo)', function(data){

            // choice_selece_val(this,1,'#p_channel');		// 运行定义默认值的效果函数
            console.log(1111)

            var ccate = $("#ccate").val();
            var id = $(".id").val();
            var alertMsg='';
            if(ccate==1){
                alertMsg='请填写要新增的省份名';
            }else if(ccate==2){
                alertMsg='请填写要新增的市名';
            }else if (ccate==3){
                alertMsg='请填写要新增的区名';
            }
            $('#channel').attr('placeholder',alertMsg);
            var url = '{:url("getCity")}';
            $.ajax({
                type: 'POST',
                url: url,
                data: {"ccate": ccate,"id":id},
                success:function(msg){
                    console.log(msg)
                    $("#p_channel").html(msg);
                    form.render('select');
                }
            })
        });


    });



    function choice_selece_val(obj,val,tar){		// 控制某个值状态下的样式
        setTimeout(function(){
            if ( $(obj).val() == val ) {
                $(tar).attr('disabled','true').css('cssText','background-color:#eee!important;');
            } else {
                $(tar).removeAttr('disabled').css('cssText','background-color:#fff!important;');
            }
        },30);
    }
</script>